package br.com.novavendas.dao;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.Transaction;

import br.com.novavendas.model.Contato;

public class DaoContato extends Dao<Contato> implements IDao<Contato>{

	public DaoContato() {
		super(Contato.class);
	}

	@Override
	public void salva(Contato objeto) throws Exception {
		Session session = super.getSession();
		Transaction tx = session.beginTransaction();
		try{	
			if (objeto.getId() == null)
				session.save(objeto);
			else
				session.update(objeto);
			tx.commit();
		}catch(Exception ex){
			ex.printStackTrace();
			throw ex;
		}finally{
			session.close();
		}	
		
	}

	@Override
	public void deleta(Contato objeto) throws Exception {
		Session session = super.getSession();
		Transaction tx = session.beginTransaction();
		try{
			session.delete(objeto); 
			tx.commit();
		}catch(Exception ex){
			ex.printStackTrace();
			throw ex;
		}finally{
			session.close();
		}
		
	}

	@Override
	public Contato getById(Contato objeto) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<Contato> listagem() throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<Contato> listagemNome(String nome) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

}
